<?php
declare (strict_types = 1);
/**
 * 公共
 * User: Luanzg
 * Date: 2020/5/22 13:38
 * Created by : vscode
 */
namespace app\common\model;

use think\Model;

class BaseModel extends Model
{

    /**
     * 详情
     */
    public function info($param = [], $field = '*')
    {
        return self::field($field)->where($param)->find();
    }

    /**
     * 列表【所有】
     */
    public function listsAll($where = [], $field = [], $order = 'create_time DESC')
    {
        return self::field($field)->where($where)->order($order)->select();
    }

    /**
     * 添加或者保存
     */
    public function addEditSave($param = [], $where = [])
    {
        if(isset($param['up_time'])) {
            $param['up_time']  = date('Y-m-d H:i:s',time());
        }
        if(isset($param['create_time'])) {
            $param['create_time'] = date('Y-m-d H:i:s',time());
        }        
        
        $save = self::where($where)->save($param);

        if ($save === false) exception('添加失败');

        return $save;
    }

    /**
     * 更新保存
     */
    public function dateUpdate($param = [], $where = [])
    {
        $update= self::where($where)->update($param);
        if ($update === false) exception('更新失败');
        return $update;
    }

    /**
     * 删除数据
     */
    public function deleteData($where = [])
    {
        return self::where($where)->delete();
    }

    /**
     * 添加
     */
    public function addSave($param = [])
    {
        $save = self::save($param);

        if ($save === false) exception('添加失败');

        return $save;
    }

}
